// 无缓冲通道
package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func RunChannel() {
	var baton = make(chan int)
	wg.Add(1)
	go Runner(baton)
	baton <- 1
	wg.Wait()
}

func Runner(baton chan int) {
	runner := <-baton

	fmt.Printf("Runner %d running with the baton\n", runner)
	fmt.Printf("Runner %d run to the line\n", runner)

	if runner == 4 {
		fmt.Printf("Runner %d Finished. Race over\n", runner)
		wg.Done()
		return
	} else {
		go Runner(baton)
		baton <- runner + 1
	}
}
